<?php 
	namespace Admin\Controller\User;
	use Admin\Controller\Auto\AutoController;
	class PersonalController extends AutoController{
		public function index(){
			$this->display();
		}
		public function update(){
			$personal = M('personal');
			$personal->create();
			// var_dump(I('post.'));die;
			$res = $personal->where(['uid'=>session('id')])->save();
			if($res){
				session('user',M('personal')->where('uid = '.session('id'))->find());
				echo 'yes';
			}else{
				echo 'no';
			}
		}
		public function sel(){
			$personal = M('personal');
			$data = $personal->where('uid = '.session('id'))->find();
			echo json_encode($data);
		}
		public function upload($rootPath){
			// return $_FILES;
			$upload = new \Think\Upload();
			$upload->maxSize=3145728;
			$upload->exts      = array('jpg', 'gif', 'png', 'jpeg');
			$upload->savePath  =  '/Uploads/'; 
			// 设置附件上传目录  
			$upload->rootPath  = $rootPath ;
			// var_dump($upload);die;
			$info = $upload->upload();
			if(!$info) {// 上传错误提示错误信息  
			    $this->error($upload->getError());  
			}else{// 上传成功 获取上传文件信息  
			    foreach($info as $file){  
					$path = trim($upload->rootPath,'.').$file['savepath'].$file['savename'];
				}
			}
			//time(); ->path  mtime();->图片
			//$_SESSION['']
			return $path;
		}
		public function shangchuan(){
			$path = $this->upload('./public/admin');
			// var_dump(session('user')['pic']=100);
			session('user',array('pic'=>'1.jpg'));
		    $personal = M('personal');
			$where = array('uid'=>session('id'));
			$pic = $personal->where($where)->find()['pic'];
			$res = $personal->where($where)->save(['pic'=>$path]);
			if($res){
				if($pic!='/public/admin/upload/images/1.jpg'){	
					if(file_exists('.'.$pic)){
						unlink('.'.$pic);
					}
				}
				session('user',M('personal')->where('uid = '.session('id'))->find());
				echo '<script type="text/javascript">
					//输出父窗口的变量
					parent.fun("yes");
				</script>';
			}else{
				echo '<script type="text/javascript">
						//输出父窗口的变量
						parent.fun("no");
					</script>';
				
			}  
		}
		public function edit(){
			$user = D('user');
			$cp = $user->find(session('id'))['password'];
			$np = md5(I('post.curpassword'));
			if($cp==$np){
				if($user->create()){
					$res = $user->where('id ='.session('id'))->save();
					if($res){
						echo 'yes';
					}else{
						echo 'no';
					}
				}
			}else{
				echo 'no';
			}
		}
		public function out(){
			session('[destroy]');
			if(empty(session('id'))){
				echo 'yes';
			}else{
				echo 'no';
			}
		}
	}

?>